<?php

class Ext_Model_UserProperty extends Ext_Db_Table
{

    protected $_name = 'sys_user_property';

    protected $_sequence = false;

    protected $_primary = array( 'user_id', 'property' 
    );

    protected $_referenceMap = array( 
		'User' => array( 
        	'columns' => 'user_id', 
            'refTableClass' => 'Ext_Model_User', 
            'refColumns' => 'user_id' 
		)
    );

    public function setUserProp( $userId, $propertyName, $propertyValue )
    {
        $property = $this->find( $userId, $propertyName )->current();
        if ( empty( $property ) ) {
            $property = $this->createRow();
            $property->user_id = $userId;
            $property->property = $propertyName;
        }
        $property->value = $propertyValue;
        $property->save();
        return true;
    }
}